<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <title>新增部门</title>
  {% include 'rbac/common/add-edit-header.html' %}
</head>
<body>
<form
  class="layui-form"
  lay-filter="department-form"
  id="department-form"
  action=""
  style="padding: 15px"
>
  <div class="layui-form-item">
    <label class="layui-form-label">部门名</label>
    <div class="layui-input-block">
      <input
        type="text"
        name="name"
        placeholder="请输入部门名"
        lay-verify="required"
        autocomplete="off"
        class="layui-input"
      />
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">负责人</label>
    <div class="layui-input-block">
      <input
        type="text"
        name="leader"
        placeholder="请输入负责人"
        lay-verify="required"
        autocomplete="off"
        class="layui-input"
      />
    </div>
  </div>
  <div class="layui-form-item">
    <label class="layui-form-label">上级部门ID</label>
    <div class="layui-input-block">
      <input
        type="text"
        name="pid"
        placeholder="请输入上级部门id"
        autocomplete="off"
        class="layui-input"
        lay-tips="若不填则新增部门为顶级部门,若填该ID对应的部门必须存在"
      />
    </div>
  </div>
  <div class="layui-form-item">
    <div class="layui-input-block">
      <button
        type="submit"
        class="layui-btn"
        lay-submit
        lay-filter="department-add-form-btn"
      >
        立即提交
      </button>
      <button type="reset" class="layui-btn layui-btn-primary">重置</button>
    </div>
  </div>
</form>
</body>
{% include 'rbac/common/add-edit-footer.html' %}
<script>
  let token = "{{ csrf_token }}";
  solve_csrf(token)

  layui.use(["form", "button", "popup"], function () {
    let form = layui.form;
    let popup = layui.popup;
    let $ = layui.$;

    form.on("submit(department-add-form-btn)", function (data) {
      // console.log(data.field); // {name: '11111', leader: '1111', pid: ''}
      let url = "/api/v1/department/add/"
      let d = data.field
      let reload_table = "department-treeTable"
      addAndEditAjaxRequest(popup, url, d, reload_table)
      return false;
    });
  });
</script>
</html>
